package cn.wetcland.urban.admin.controller;

import cn.wetcland.urban.admin.dto.AdminLoginDTO;
import cn.wetcland.urban.admin.dto.CustomerUpdateDTO;
import cn.wetcland.urban.admin.dto.DriverUpdateDTO;
import cn.wetcland.urban.admin.service.UtAdminService;
import cn.wetcland.urban.admin.service.UtCustomerService;
import cn.wetcland.urban.admin.service.UtDriverService;
import cn.wetcland.urban.admin.vo.AdminLoginVO;
import cn.wetcland.urban.common.AjaxResponse;
import cn.wetcland.urban.generator.domain.UtCustomer;
import cn.wetcland.urban.generator.domain.UtDriver;
import cn.wetcland.urban.generator.dto.BaseConditionSearchDTO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    public UtCustomerService customerService;

    @Resource
    public UtDriverService driverService;

    @Resource
    public UtAdminService adminService;

    @GetMapping("/customerList")
    public AjaxResponse customerList(BaseConditionSearchDTO searchDTO) {
        Page<UtCustomer> customerPage = customerService.customerList(searchDTO);
        return AjaxResponse.success(customerPage);
    }

    @GetMapping("/driverList")
    public AjaxResponse driverList(BaseConditionSearchDTO searchDTO) {
        Page<UtDriver> driverPage = driverService.driverList(searchDTO);
        return AjaxResponse.success(driverPage);
    }

    @PostMapping("/adminLogin")
    public AjaxResponse adminLogin(@RequestBody AdminLoginDTO adminLoginDTO) {
        AdminLoginVO adminLoginVO = adminService.handleAdminLogin(adminLoginDTO);
        return AjaxResponse.success(adminLoginVO);
    }

    @PutMapping("/customerBanOrUnban/{customerId}")
    public AjaxResponse customerBanOrUnban(@PathVariable Long customerId) {
        customerService.handleCustomerBanOrUnban(customerId);
        return AjaxResponse.success();
    }

    @PutMapping("/driverBanOrUnban/{driverId}")
    public AjaxResponse driverBanOrUnban(@PathVariable Long driverId) {
        driverService.handleDriverBanOrUnban(driverId);
        return AjaxResponse.success();
    }

    @DeleteMapping("/driverDelete/{driverId}")
    public AjaxResponse driverDelete(@PathVariable Long driverId) {
        driverService.handleDriverDelete(driverId);
        return AjaxResponse.success();
    }

    @DeleteMapping("/customerDelete/{customerId}")
    public AjaxResponse customerDelete(@PathVariable Long customerId) {
        customerService.handleCustomerDelete(customerId);
        return AjaxResponse.success();
    }

    @PutMapping("/customerUpdate")
    public AjaxResponse customerUpdate(@RequestBody CustomerUpdateDTO updateDTO) {
        customerService.handleCustomerUpdate(updateDTO);
        return AjaxResponse.success();
    }

    @PutMapping("/driverUpdate")
    public AjaxResponse driverUpdate(@RequestBody DriverUpdateDTO updateDTO) {
        driverService.handleDriverUpdate(updateDTO);
        return AjaxResponse.success();
    }

}
